﻿@model LeadMaster.Models.LeadStatus

@using (Ajax.BeginForm(
    "ChangeLeadReason", "QC", null,
    new AjaxOptions
    {
        HttpMethod = "Post"
    }, new { @id = "formChangeReason" }))
{    
@Html.ValidationSummary(true)
<fieldset>
<legend>Change Reason Of This Lead</legend>
@Html.HiddenFor(m => m.LeadStatusID)
@Html.HiddenFor(m => m.BlockID)
@Html.HiddenFor(m => m.LeadFlagsID)
@Html.HiddenFor(m => m.LeadID)
@Html.HiddenFor(m => m.CallCentreID)
@Html.HiddenFor(m => m.LeadDate)
@Html.HiddenFor(m => m.VoxFile)
@Html.HiddenFor(m => m.PurchaseOrderID)
@Html.HiddenFor(m => m.LeadReasonsID)
@Html.HiddenFor(m => m.Manfield)
@Html.HiddenFor(m => m.ClientNotes)
<div>
<div>
<label>The Client has Returned this lead based on :&nbsp; </label><label style="font-family: Arial, Helvetica, sans-serif; font-weight: bold; font-size: larger">@Model.LeadReason.Description</label>
</div>
<div>
<label style="font-family: Arial, Helvetica, sans-serif; font-size: smaller; color: #990000">Please ensure that your Notes do not give any specific Client information away as these are now being read by the Call Centre</label>
</div>
<div class="spacer"></div>
<table class="listtable contactstable" cellspacing="0" cellpadding="0" style="width: 850px;" id="enquirylist">
    <tr>
    <th style="text-align: left"><label>External Reason</label></th>
    <td style="border-style: none">
    <select id="QCLeadReasonsID" name="QCLeadReasonsID">
    <option value="1">Please select a valid Reason</option>
    @foreach (var item in ViewBag.QCLeadReasonsID)
    {
        <option value="@(item.LeadReasonsID)" data-inforequired="@(item.InfoRequired)" data-infoprompt="@(item.InfoPrompt)" id="option@(item.LeadReasonsID)"
        @if (item.LeadReasonsID == Model.QCLeadReasonsID)
	{
		 @:selected
	}
        >@item.Description</option>
    }
    </select>
    </tr>
    <tr>
    <th><label>Internal Reason</label></th>
    <td style="border-style: none">
    <select id="QCManfield" name="QCManfield">
    <option value="0">Please select a Mandatory Field</option>
    @foreach (var item in ViewBag.QCManfield)
    {
        <option value="@(item)"
        @if (Model.QCManfield==item)
        {
         @:selected   
        }
        >@item.Substring(0, item.Length<100 ? item.Length : 100)</option>
    }
    </select>
    </td>
    </tr>
    <tr>
    <th style="text-align: left">
    <label id="infoheading"></label>
    </th>
    <td style="border-style: none" id="cellinfo">
    <label>@Model.Notes</label>
    <textarea class="returnnotes" id="newnote" name="newnote"></textarea>
    </td>
    </tr>
</table>
</div>
@Html.HiddenFor(m => m.Notes)
</fieldset>
}

<script type="text/javascript">
    $(document).ready(function () {

        TakeNote("@(Model.LeadReasonsID)");

        $('#QCLeadReasonsID').change(function () {
            var optionSelected = $(this).val();
            TakeNote(optionSelected);
        });

        function TakeNote(optionSelected) {
            if ($("#option" + optionSelected).data("inforequired") == "True") {
                $('#infoheading').text($("#option" + optionSelected).data("infoprompt"));
            }
        }

        $('#QCLeadReasonsID').blur(function () {
            if ($('#QCLeadReasonsID').val() > 1) {
                $('#QCManfield').val(0);
            }
        });
    });
</script>
